package br.com.avaliacao.model.dao;

import br.com.avaliacao.model.entities.Colaborador;
import br.com.avaliacao.utils.HibernateUtil;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Maicon
 */
public class ColaboradorDAO implements CRUD<Colaborador> {

    @Override
    public boolean inserir(Colaborador obj) {
        Session s = HibernateUtil.getSessao().openSession();
        Transaction t = s.beginTransaction();
        s.save(obj);
        t.commit();
        return true;
    }

    @Override
    public boolean atualizar(Colaborador obj) {
        Session s = HibernateUtil.getSessao().openSession();
        Transaction t = s.beginTransaction();
        s.update(obj);
        t.commit();
        return true;
    }

    @Override
    public boolean excluir(Colaborador obj) {
        Session s = HibernateUtil.getSessao().openSession();
        Transaction t = s.beginTransaction();
        s.delete(obj);
        t.commit();
        return true;
    }

    @Override
    public Colaborador consultar(int id) {
        Session s = HibernateUtil.getSessao().openSession();
        return (Colaborador) s.load(Colaborador.class, id);
    }

    @Override
    public List<Colaborador> retLista() {
        Session s = HibernateUtil.getSessao().openSession();
        Transaction t = s.beginTransaction();
        List<Colaborador> lista = s.createQuery("from Colaborador").list();
        t.commit();
        return lista;
    }
}
